<?php
namespace Home\Model;
use Think\Model;
class UserModel extends Model {

    public function checkEmail($email){

        //$res=$this->where("email='{$email}'")->select();
//        return $res;
        $sql="select * from user where email='{$email}'";
        $res=$this->query($sql);
//        var_dump($res);exit();
        return $res;
    }

    public function checknickname($name){
     //   $res=$this->where("nickname='{$name}'")->select();
//        return $res;
        $sql="select * from user where nickname='{$name}'";
        $res=$this->query($sql);
//        var_dump($res);exit();
        return $res;

    }

    public function checkpass($email){
        $sql="select password from user where email='{$email}' ";
        $res=$this->query($sql);
        $res=current($res)['password'];
        return $res;
    }

    public function getnickname($email){
        $sql="select nickname,face,id from user where email='{$email}' ";
        $res=$this->query($sql);
        $res['nickname']=current($res)['nickname'];
        $res['id']=current($res)['id'];
        $res['face']=current($res)['face'];
        return $res;
    }

    public function getarr($id){
        $sql="select nickname,face,password,city,sex,email,sign,kiss,create_time from user where id='{$id}'";
        $res=$this->query($sql);
        $arr['nickname']=current($res)['nickname'];
        $arr['face']=current($res)['face'];
        $arr['pass']=current($res)['password'];
        $arr['city']=current($res)['city'];
        $arr['sex']=current($res)['sex'];
        $arr['email']=current($res)['email'];
        $arr['sign']=current($res)['sign'];
        $arr['id']=$id;
        $arr['kiss']=current($res)['kiss'];
        $arr['create_time']=current($res)['create_time'];
        return $arr;
    }

    public function acheckemail($email,$id){
        $sql="select email from user where id <> '{$id}' and email ='{$email}'";
         $res=$this->query($sql);
         return $res;
    }

    public function achecknickname($nickname,$id){
        $sql="select email from user where id <> '{$id}' and nickname ='{$nickname}'";
        $res=$this->query($sql);
//        var_dump($sql);exit();
        return $res;
    }

    public function getfn($id){
        $sql="select nickname,face from user where id='{$id}' ";
        $res=$this->query($sql);
        $res['nickname']=current($res)['nickname'];
        $res['face']=current($res)['face'];
        return $res;
    }

    public function cx($id){
        $_SESSION['nickname']=$this->getfn($id)['nickname'];

        $_SESSION['face']=$this->getfn($id)['face'];

    }

}